﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dao;

namespace Web.Page
{
    public partial class ZL_GYS_Add : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.lblTitle.Text = "新增供应商";
            }
        }

        /// <summary>
        /// 清空所有TextBox内容
        /// </summary>
        private void ClearControlsValue()
        {
            this.lbResult.Text = "";
            this.tbBH.Text = "";
            this.tbMC.Text = "";
            this.tbBZ.Text = "";
            this.tbDZ.Text = "";
            this.tbFRDB.Text = "";
            this.tbGSCZ.Text = "";
            this.tbGSDH.Text = "";
            this.tbLXR.Text = "";
            this.tbLXRCZ.Text = "";
            this.tbLXRDH.Text = "";
            this.tbLXRSJ.Text = "";
        }

        protected void btnSave_Click(object sender, ImageClickEventArgs e)
        {
            this.lbResult.Text = "";
            ZL_GYS entity = new ZL_GYS()
            {
                ID = Guid.NewGuid(),
                BH = this.tbBH.Text.Trim(),
                MC = this.tbMC.Text.Trim(),
                FRDB = this.tbFRDB.Text.Trim(),
                GSDH = this.tbGSDH.Text.Trim(),
                GSCZ = this.tbGSCZ.Text.Trim(),
                LXR = this.tbLXR.Text.Trim(),
                LXRCZ = this.tbLXRCZ.Text.Trim(),
                LXRDH = this.tbLXRDH.Text.Trim(),
                LXRSJ = this.tbLXRSJ.Text.Trim(),
                DZ = this.tbDZ.Text.Trim(),
                BZ = this.tbBZ.Text.Trim()
            };

            string resultMessage = "";
            try
            {
                ZL_GYS_Dao dao = new ZL_GYS_Dao();
                int result = dao.Add(entity);

                if (result == 1)
                {
                    resultMessage = "保存成功";
                    ClearControlsValue();
                }
            }
            catch (Exception ex)
            {
                resultMessage = "保存失败" + ex.Message;
            }
            finally
            {
                this.lbResult.Text = resultMessage;
            }
        }

        protected void btnClear_Click(object sender, ImageClickEventArgs e)
        {
            ClearControlsValue();
        }

        protected void btnReturn_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("ZL_GYS_Query.aspx");
        }
    }
}